package com.elder.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.elder.business.domain.ApartmentBanner;
import com.elder.business.domain.ElderlyStatisticsDTO;
import com.elder.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.elder.common.annotation.Log;
import com.elder.common.core.controller.BaseController;
import com.elder.common.core.domain.AjaxResult;
import com.elder.common.enums.BusinessType;
import com.elder.business.domain.Elderlyapartment;
import com.elder.business.service.IElderlyapartmentService;
import com.elder.common.utils.poi.ExcelUtil;
import com.elder.common.core.page.TableDataInfo;

/**
 * 公寓信息Controller
 * 
 * @author zyk
 * @date 2023-11-26
 */
@RestController
@RequestMapping("")
public class ElderlyapartmentController extends BaseController
{
    @Autowired
    private IElderlyapartmentService elderlyapartmentService;

    /**
     * 查询公寓信息列表
     */
    @Anonymous
    @GetMapping("/business/elderlyapartment/list")
    public TableDataInfo list(Elderlyapartment elderlyapartment)
    {
        startPage();
        List<JSONObject> list = elderlyapartmentService.selectElderlyapartmentList(elderlyapartment);
        return getDataTable(list);
    }

    /**
     * 导出公寓信息列表 暂不需要
     */
//    @PreAuthorize("@ss.hasPermi('business:elderlyapartment:export')")
//    @Log(title = "公寓信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Elderlyapartment elderlyapartment)
//    {
//        List<Elderlyapartment> list = elderlyapartmentService.selectElderlyapartmentList(elderlyapartment);
//        ExcelUtil<Elderlyapartment> util = new ExcelUtil<Elderlyapartment>(Elderlyapartment.class);
//        util.exportExcel(response, list, "公寓信息数据");
//    }

    /**
     * 获取公寓信息详细信息
     */
    @GetMapping(value = "/business/elderlyapartment/{apartmentId}")
    public AjaxResult getInfo(@PathVariable("apartmentId") Long apartmentId)
    {
        return success(elderlyapartmentService.selectElderlyapartmentByApartmentId(apartmentId));
    }

    /**
     * 新增公寓信息
     */
    @Log(title = "公寓信息", businessType = BusinessType.INSERT)
    @PostMapping("/business/elderlyapartment")
    public AjaxResult add(@RequestBody Elderlyapartment elderlyapartment)
    {
        return toAjax(elderlyapartmentService.insertElderlyapartment(elderlyapartment));
    }

    /**
     * 修改公寓信息
     */
    @PreAuthorize("@ss.hasPermi('business:elderlyapartment:edit')")
    @Log(title = "公寓信息", businessType = BusinessType.UPDATE)
    @PutMapping("/business/elderlyapartment")
    public AjaxResult edit(@RequestBody Elderlyapartment elderlyapartment)
    {
        return toAjax(elderlyapartmentService.updateElderlyapartment(elderlyapartment));
    }

    /**
     * 删除公寓信息
     */
    @Anonymous
    @Log(title = "公寓信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/business/elderlyapartment/{apartmentIds}")
    public AjaxResult remove(@PathVariable Long[] apartmentIds)
    {
        return toAjax(elderlyapartmentService.deleteElderlyapartmentByApartmentIds(apartmentIds));
    }

    /***
     * @description 获取所有公寓信息
     * @return TableDataInfo
     * @author zyk
     * @date 2023/12/7 20:14
     */
    @Anonymous
    @RequestMapping("/business/elderlyapartment/allList")
    public TableDataInfo getElderApartmentList(){
        JSONArray list = elderlyapartmentService.getAllElderApartment();
        return getDataTable(list);
    }

    /***
     * @description 获取公寓入住统计
     * @return AjaxResult
     * @author zyk
     * @date 2023/12/7 20:15
     */
    @Anonymous
    @RequestMapping("/business/elderlyapartment/Statistics")
    public AjaxResult getApartmentStatistics(){
        ElderlyStatisticsDTO data = elderlyapartmentService.getApartmentStatistics();
        return AjaxResult.success("success",data);
    }

    /***
     * @description 获取公寓banner列表
     * @return TableDataInfo
     * @author zyk
     * @date 2024/2/29 16:44
     */
    @Anonymous
    @RequestMapping("/apartment/getBannerList")
    public TableDataInfo getBannerList(){
        return elderlyapartmentService.getApartmentBannerList();
    }

    /***
     * @description 获取公寓banner
     * @param bannerId
     * @return JSONObject
     * @author zyk
     * @date 2024/2/29 16:43
     */
    @Anonymous
    @RequestMapping("/apartment/getBanner")
    public JSONObject getBanner(Long bannerId){
        return elderlyapartmentService.getApartmentBanner(bannerId);
    }

    /***
     * @description 添加公寓banner
     * @param banner
     * @return AjaxResult
     * @author zyk
     * @date 2024/2/29 16:43
     */
    @Anonymous
    @RequestMapping("/apartment/addBanner")
    public AjaxResult addBanner(@RequestBody ApartmentBanner banner){
        return elderlyapartmentService.addApartmentBanner(banner);
    }

    /***
     * @description 修改公寓banner
     * @param banner
     * @return AjaxResult
     * @author zyk
     * @date 2024/2/29 16:43
     */
    @Anonymous
    @RequestMapping("/apartment/updateBanner")
    public AjaxResult updateBanner(@RequestBody ApartmentBanner banner){
        return elderlyapartmentService.updateApartmentBanner(banner);
    }

    /***
     * @description 删除公寓banner
     * @param bannerId
     * @return AjaxResult
     * @author zyk
     * @date 2024/2/29 16:43
     */
    @Anonymous
    @RequestMapping("/apartment/delBanner")
    public AjaxResult delBanner(Long bannerId){
        return elderlyapartmentService.delApartmentBanner(bannerId);
    }

    @Anonymous
    @RequestMapping("/apartment/RoomTree")
    public String getElderApartMentRoomBedList(){
        return elderlyapartmentService.getElderApartMentRoomBedList().toJSONString();
    }

    @Anonymous
    @RequestMapping("/apartment/getRoomType")
    public String getRoomType(){
        return elderlyapartmentService.getRoomType().toJSONString();
    }

}
